//
//  PPActivityDetailViewController.m
//  pet
//
//  Created by 陈无忌 on 9/6/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPActivityDetailViewController.h"
#import "supportingHeadFiles.h"
#import "UMSocial.h"

@interface PPActivityDetailViewController ()<UMSocialUIDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *activityWebView;
@property (strong, nonatomic) NSString *webAdress;

@end

@implementation PPActivityDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.webAdress = [NSString stringWithFormat:@"http://pet.fundoing.cn/notification/activity?id=%d",self.activity.id];
    
    [self loadWebPageWithString:self.webAdress];
}

- (void)loadWebPageWithString:(NSString*)urlString
{
    NSURL *myUrl =[NSURL URLWithString:urlString];
    NSURLRequest *request =[NSURLRequest requestWithURL:myUrl];
    [self.activityWebView loadRequest:request];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)share:(UIBarButtonItem *)sender {
    
    NSData *data = [NSData dataWithContentsOfURL:[PPImageUrl getImageUrlOriginal:self.activity.imgUrl]];
    UIImage *shareImage = [UIImage imageWithData:data];

//    [UMSocialSnsService handleOpenURL:[NSURL URLWithString:self.webAdress]];
    
    
    [UMSocialData defaultData].extConfig.wechatSessionData.url = self.webAdress;
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.webAdress;
    [UMSocialData defaultData].extConfig.qqData.url = self.webAdress;
    [UMSocialData defaultData].extConfig.qzoneData.url = self.webAdress;

    [UMSocialSnsService presentSnsController:self appKey:@"54a44f54fd98c59ae100082f" shareText:self.activity.title shareImage:shareImage shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToSms,UMShareToSina,UMShareToQzone,UMShareToEmail,nil] delegate:self];
    
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}

@end
